package com.ruoyi.complaint.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.complaint.entity.Complaint;
import com.ruoyi.complaint.service.ComplaintService;
import com.ruoyi.complaint.service.OrderContractController;
import com.ruoyi.complaint.service.WaybillController;
import com.ruoyi.system.api.domain.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author dxw
 * @date 2022-04-21
 */
@RestController
@RequestMapping("/complaint")
public class ComplaintController extends BaseController {
    @Resource
    private ComplaintService complaintService;

    @Resource
    private OrderContractController orderContractController;

    @Resource
    private WaybillController waybillController;


    @GetMapping("/getAll")
    public TableDataInfo getall(Complaint complaint) {
        startPage();
        List<Complaint> list = complaintService.getall(complaint);
        return getDataTable(list);
    }
    @GetMapping("/getAll2")
    public TableDataInfo getall2(Complaint complaint) {
        startPage();
        List<Complaint> list = complaintService.getall2(complaint);
        return getDataTable(list);
    }

    @DeleteMapping("/ignoreComplaint/{id}")
    public AjaxResult ignoreComplaint(@PathVariable("id") int id) {
        return AjaxResult.success(complaintService.ignoreComplaint(id));
    }

    @PutMapping("/changeStatus/{status}/{name}/{id}")
    public AjaxResult changeStatus(@PathVariable("id") int id, @PathVariable("name") String name, @PathVariable("status") int status) {
        return AjaxResult.success(complaintService.changeStatus(id, name,status));
    }
    @PutMapping("/changeStatus2/{name}/{id}")
    public AjaxResult changeStatus2(@PathVariable("id") int id, @PathVariable("name") String name) {
        return AjaxResult.success(complaintService.changeStatus(id, name,2));
    }

    @PutMapping("/rollbackComplaint/{id}")
    public AjaxResult rollbackComplaint(@PathVariable("id") int id) {
        return AjaxResult.success(complaintService.rollbackComplaint(id));
    }

    @GetMapping("/getStatics/{id}")
    public AjaxResult getStatics(@PathVariable("id") int id) {
        return AjaxResult.success(complaintService.getStatics(id));
    }

    //以下是代码生成器生成的代码---------------------------------------------------------------------------------

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Complaint complaint) {
        startPage();
        List<Complaint> list = complaintService.selectComplaintList(complaint);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Complaint complaint) {
        List<Complaint> list = complaintService.selectComplaintList(complaint);
        ExcelUtil<Complaint> util = new ExcelUtil<Complaint>(Complaint.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(complaintService.selectComplaintById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Complaint complaint) {
        return toAjax(complaintService.insertComplaint(complaint));
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Complaint complaint) {
        return toAjax(complaintService.updateComplaint(complaint));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(complaintService.deleteComplaintByIds(ids));
    }
}
